﻿#ifndef XRTCCLIENT_XRTC_IXRTC_ENGINE_H_
#define XRTCCLIENT_XRTC_IXRTC_ENGINE_H_

#include <vector>

#include "xrtc/xrtc_defines.h"
#include "xrtc/ixrtc_media_source.h"
#include "xrtc/ixrtc_preview.h"
#include "xrtc/ixrtc_pusher.h"
#include "xrtc/ixrtc_player.h"

namespace xrtc {

enum class XRTCError {
    kNoErr = 0,
    kVideoSourceNotInit = -999,
    kVideoSourceStartErr,
    kStartPushRequestOfferErr,
    kStartPushSendAnswerErr,
    kStartPushSocketError,
    kStopPushRequestErr,
    kStartPullRequestOfferErr,
    kStartPullSendAnswerErr,
};

class XRTCEngineObserver {
public:
    virtual ~XRTCEngineObserver() {}

    virtual void OnVideoSourceStartEvent(IXRTCMediaSource* video_source,
        XRTCError err) {
    }
    virtual void OnVideoSourceStopEvent(IXRTCMediaSource* video_source,
        XRTCError err) {
    }

    virtual void OnPushStreamState(IXRTCPusher* pusher,
        XRTCStreamState state) {
    }
    virtual void OnStartPushEvent(IXRTCPusher* pusher,
        XRTCError err) {
    }
    virtual void OnStopPushEvent(IXRTCPusher* pusher,
        XRTCError err) {
    }
    virtual void OnStartPullEvent(IXRTCPlayer* player,
        XRTCError err) {
    }
    virtual void OnStopPullEvent(IXRTCPlayer* player,
        XRTCError err) {
    }
    virtual void OnPullStreamState(IXRTCPlayer* player,
        XRTCStreamState state) {
    }
    virtual void OnRemotePeerLeaveEvent() {}
};

class IXRTCEngine {
public:
    virtual ~IXRTCEngine() {}

    // 获取视频设备列表信息
    virtual std::vector<XRTCDeviceInfo> GetVideoDeviceList() = 0;

    // 获取音频设备列表信息
    virtual std::vector<XRTCDeviceInfo> GetAudioDeviceList() = 0;

    // 创建一个视频源
    virtual IXRTCVideoSource* CreateVideoSource(const XRTCVideoConfig& video_config) = 0;
    
    // 销毁视频源
    virtual void DestroyVideoSource(IXRTCMediaSource* video_source) = 0;

    // 创建视频预览对象
    virtual IXRTCPreview* CreatePreview(IXRTCVideoSource* video_source,const XRTCCanvas& canvas) = 0;
    
    // 销毁视频预览对象
    virtual void DestroyPreview(IXRTCPreview* preview) = 0;

    // 创建推流对象
    virtual IXRTCPusher* CreatePusher() = 0;
    
    // 销毁推流对象
    virtual void DestroyPusher(IXRTCPusher* pusher) = 0;


    // 创建拉流对象
    virtual IXRTCPlayer* CreatePlayer() = 0;

    // 销毁拉流对象
    virtual void DestroyPlayer(IXRTCPlayer* player) = 0;

};

IXRTCEngine* CreateXRTCEngine(XRTCEngineObserver* observer);

void DestroyXRTCEngine(IXRTCEngine* engine);

} // namespace xrtc

#endif // XRTCCLIENT_XRTC_IXRTC_ENGINE_H_